﻿using System.Collections.Generic;
using System.Linq;

namespace TestSystem.Model.Data.Repositories
{
    public class FrequencyRepository
    {
        private TestSystemEntities entities = new TestSystemEntities();

        public IQueryable <Frequency> FindAll()
        {
            return entities.Frequencies.AsQueryable();
        }
        public void Insert(int ToolId)
        {
            foreach (var frequencyType in entities.FrequencyTypes)
            {
                entities.AddToFrequencies(new Frequency { ToolId = ToolId, FrequencyTypeId = frequencyType.Id });
            }
        }
        public void Delete(int ToolId)
        {
            var currentFrequencies = entities.Frequencies.Where(t => t.ToolId == ToolId);
            foreach (var currentFrequency in currentFrequencies)
            {
                entities.DeleteObject(currentFrequency);
            }

        }
        public void Save()
        {
            entities.SaveChanges();
        }
    }
}   
